package com.dibang.app.operation.control.impl;

import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dibang.app.R;
import com.dibang.app.mvp.abs.AbsControl;
import com.dibang.app.mvp.util.Tu;
import com.dibang.app.operation.control.abs.IssueGroupControl;
import com.dibang.app.operation.model.abs.IssueGroupModel;
import com.dibang.app.operation.presenter.abs.IssueGroupPresenter;
import com.dibang.app.operation.provider.IssueGroupProImpl;
import com.dibang.app.operation.view.abs.IssueGroupView;
import com.dibang.app.view.ViewHelper;
import com.dx.dxloadingbutton.lib.LoadingButton;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by wxl on 2019/7/24.
 *
 */

public class IssueGroupControlImpl extends AbsControl<IssueGroupView, IssueGroupPresenter, IssueGroupModel, IssueGroupProImpl> implements IssueGroupControl {

    @BindView(R.id.main_group_total_num_layout)
    LinearLayout totalLayout;

    @BindView(R.id.main_group_total_num_text_view)
    TextView totalTextView;

    @BindView(R.id.main_group_had_num_layout)
    LinearLayout hadLayout;

    @BindView(R.id.main_group_had_num_text_view)
    TextView hadTextView;

    @BindView(R.id.main_group_remark_layout)
    LinearLayout remarkLayout;

    @BindView(R.id.main_group_remark_text_view)
    TextView remarkTextView;

    @BindView(R.id.main_group_submit_view)
    LoadingButton submitView;

    private int totalNumber = 0;


    public IssueGroupControlImpl(@NonNull View targetView) {
        super(targetView);
        ButterKnife.bind(this, targetView);
        ViewHelper.setLoadingButtonBackgroundShader(submitView);
        totalTextView.setHint("去选择");
        hadTextView.setHint("去选择");
        remarkTextView.setHint("选择备注");
    }


    @OnClick(R.id.main_group_total_num_layout)
    public void onTotalNumViewClick(View v) {
        getView().onShowGroupTip(1,7,"请选择拼团人数",rootView);

    }

    @OnClick(R.id.main_group_had_num_layout)
    public void onHadNumViewClick(View v) {
        if(totalNumber == 0){
            Tu.get().tu("请先选择拼车总人数~");
        } else {
            getView().onShowGroupTip(2, totalNumber, "请选择人数", rootView);
        }
    }

    @OnClick(R.id.main_group_remark_layout)
    public void onRemarkViewClick(View v) {
        getView().onShowGroupTip(3, 1, "备注", rootView);
    }

    @OnClick(R.id.main_group_submit_view)
    public void onSubmitViewClick(View v) {
        submitView.startLoading();
    }

    @Override
    public void onSelectNumber(int type, int number) {
        if(type == 1){
            totalNumber = number;
            totalTextView.setText(number+"人");
            hadTextView.setHint("去选择");
        } else {
            hadTextView.setText(number+"人");
        }
    }


    @Override
    public void onRemarkBuffer(String buffer) {
        if(TextUtils.isEmpty(buffer)){
            remarkTextView.setText("选择备注");
        } else {
            remarkTextView.setText(buffer);
        }
    }
}
